/*
 * SPI.c
 *
 * Created: 1/18/2013 1:50:37 PM
 *  Author: Alexander
 */ 
#include "SPI.h"

void InitSPI(void)
{
	DDRB = (1<<PB2)|(1<<PB1);	 // Set MOSI , SCK , and SS output
	SPCR = ((1<<SPE)|(1<<MSTR) |(1<<CPHA)|(1<<CPOL)|(1<<SPR0));	// Enable SPI, Master, set clock rate fck/16, SPI mode 3
}

void InitPressureSPI(void)
{
		DDRB = (1<<PB2)|(1<<PB1);        // Set MOSI , SCK , and SS output
		SPCR = ((1<<SPE)|(1<<MSTR) |(1<<SPR0));    // Enable SPI, Master, set clock rate fck/16, spi mode 0, MSB first
}

void WriteByteSPI(uint8_t byte)
{
	
	SPDR = byte;					//Load byte to Data register
	while(!(SPSR & (1<<SPIF))); 	// Wait for transmission complete

}

uint8_t ReadByteSPI(uint8_t addr)
{
	SPDR = addr;					//Load byte to Data register
	while(!(SPSR & (1<<SPIF)))
	{
	//	AvrXYieldHack(10); //loop until bit is set
	}
	return SPDR;
}